﻿@model PrivateMessageListModel
@inject Grand.Services.Localization.ILocalizationService localizationService
<div class="private-messages-box">
    <script asp-location="Footer">
        $(document).ready(function () {

            $('#selectall-sent').click(function () {
                $('#pm-sent-table .rowcheckbox').prop('checked', $(this).is(':checked')).change();
            });

            $('#pm-sent-table .rowcheckbox').on('change', function (e) {
                var numChkBoxes = $('#pm-sent-table .rowcheckbox').length;
                var numChkBoxesChecked = $('#pm-sent-table .rowcheckbox:checked').length;
                $('#selectall-sent').prop('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
            });
        });
    </script>
    @if (Model.Messages.Any())
    {
        <form asp-route="PrivateMessagesSent" method="post">
            <div class="table-responsive">
                <table class="table table-hover data-table" id="pm-sent-table">
                    <colgroup>
                        <col />
                    </colgroup>
                    <thead class="table-inverse">
                        <tr>
                            <th>
                                <div class="col-12">
                                    <div class="row">
                                        <div class="select col-1">
                                            <label class="custom-control custom-checkbox">
                                                <input type="checkbox" id="selectall-sent" class="custom-control-input">
                                                <span class="custom-control-label"></span>
                                                <span class="custom-control-description">&nbsp;</span>
                                            </label>
                                        </div>
                                        <div class="to col-2 d-none d-md-block">
                                            @T("PrivateMessages.Inbox.ToColumn")
                                        </div>
                                        <div class="subject col-5 d-none d-md-block">
                                            @T("PrivateMessages.Inbox.SubjectColumn")
                                        </div>
                                        <div class="date col-4 d-none d-md-block">
                                            @T("PrivateMessages.Inbox.DateColumn")
                                        </div>
                                    </div>
                                </div>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @for (int i = 0; i < Model.Messages.Count; i++)
                        {
                            var item = Model.Messages[i];
                        <tr @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))>
                            <td>
                                <div class="col-12">
                                    <div class="row text-center text-sm-left">
                                        <div class="select col-sm-1 col-12 text-left">
                                            <label class="custom-control custom-checkbox">
                                                <input name="si@(item.Id)" id="pm@(item.Id)" type="checkbox" class="custom-control-input rowcheckbox">
                                                <span class="custom-control-label"></span>
                                                <span class="custom-control-description">&nbsp;</span>
                                            </label>
                                        </div>
                                        <div class="from col-sm-2 col-12 pb-1">
                                            @if (item.AllowViewingFromProfile)
                                            {
                                                @Html.RouteLink(item.CustomerFromName, "CustomerProfile", new { Id = item.FromCustomerId })
                                            }
                                            else
                                            {
                                                @item.CustomerFromName
                                            }
                                        </div>
                                        <div class="subject col-sm-5 col-12">
                                            @Html.RouteLink(item.Subject, "ViewPM", new { privateMessageId = item.Id }, new { @class = (item.IsRead) ? "pm-read" : "pm-unread" })
                                        </div>
                                        <div class="date col-sm-4 col-12">
                                            @item.CreatedOn
                                        </div>
                                    </div>
                                </div>
                            </td>

                        </tr>
                        }
                    </tbody>
                </table>
            </div>
            @{ var pager = Html.Pager(localizationService, Model.PagerModel);}
            @if (pager!=null)
            {
                <div class="pager">
                    @pager
                </div>
            }
            <div class="buttons mb-2">
                <input class="btn btn-secondary delete-selected-pm-button" name="delete-sent" type="submit" value="@T("PrivateMessages.Inbox.DeleteSelected")" />
            </div>
        </form>
    }
</div>
